<%@ page language="java" contentType="text/html; charset=UTF-8"
    pageEncoding="UTF-8"%>
<%@page import="java.util.*"%>
<%@page import="com.is.model.*" %>
<%@page import="com.is.control.*" %>
<%@page import="com.is.util.ParamUtil"%>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<link rel="shortcut icon" href="/InterStu/resources/image/favicon.ico" />
<link rel="stylesheet" type="text/css" href="../../resources/css/all.css" />
<link rel="stylesheet" type="text/css" href="../../resources/css/user_add.css" />
<link href="../../resources/css/default.css" rel="stylesheet" type="text/css" />
<script type="text/javascript" src="../../resources/js/jquery-1.8.1.js"></script>
<script type="text/javascript" src="../../resources/js/jquery.artDialog.js"></script>
<script type="text/javascript" src="../../resources/js/iframeTools.js"></script>
<script type="text/javascript" src="../../resources/js/popUpWin.js"></script>
<script type="text/javascript" src="../../resources/js/WebCalendar.js"></script>
<script type="text/javascript">
	(function (config) {
	    config['fixed'] = true;
	    config['okVal'] = '确定';
	    config['cancelVal'] = '取消';
		config['skin'] = 'default';
		config['drag'] = 'true';
	    // [more..]
	})(art.dialog.defaults);
	$(function(){
		/*删除信息时输入口令*/
		$(".deleteUser").click(function(){
			
		})
		$(".update").click(function(){
			$.dialog.open("/InterStu/update_info.jsp",{width:460,height:400,title:"个人信息"});
		})
		var block = $("#magic_block");
		if($(".active a").position()){
			block.css("top",$(".active a").position().top+10)
			.data("oriTop",$(".active a").position().top)
		}
		$(".nav ul li").find("a").hover(
			function(){
				var $this = $(this);
				var newTop = $this.position().top;
				block.stop().animate({
					top:newTop+10
				})
			},
			function(){
				block.stop().animate({
					top:block.data("oriTop")+10
				})
			}
		)
		var role = document.getElementsByName("role");
		for(var i = 0 ;i < role.length;i++){
			role[i].onchange = function(){
				document.forms["condition"].submit();
			}
		}
		$('#add_info').hide();
		$('.add_info').click(function(){
			document.forms['add_form'].action="user_add_do.jsp";
			$(":text").removeClass("nontxt");
			$(":text").focus(function(){
				$(this).removeClass("nontxt");
			})
			.mouseover(function(){
				$(this).removeClass("nontxt");
			})
			.blur(function(){
				$(this).removeClass("nontxt");
			})
			.mouseout(function(){
				$(this).removeClass("nontxt");
			})
			$("input[name='add_name']").val(null).attr("readonly",false);
			$("input[name='add_username']").val(null).attr("readonly",false);
			//var key=(Math.random()+"").substring(2,8);
			var key="123456";
			$("input[name='add_password']").val(key);
			$("input[name='add_picPath']").val(null);
			$("#imgs").attr("src","../../resources/image/man.GIF");
			$("input[name='add_position']").val(null);
			$("input[name='add_political']").val(null);
			$("input[name='add_birthday']").val(null);
			$("input[name='add_edulevel']").val(null);
			$("input[name='add_email']").val(null);
			$("input[name='add_phone']").val(null);
			$("[name='add_professional']").val(null);
			$("input[name='add_role']").val(null);
			$("[name='add_sex']").each(function(i){
				$(this).attr("checked",false);
				if($(this).val() == "0")
				$(this).attr("checked",true);
			});
			$("[name='add_role']").find("option").each(function(i){
				$(this).attr("selected",false);
				if($(this).val() == "0"){
					$(this).attr("selected",true);
				}
			});
			$.dialog({
				title:'添加教工信息',
				content: document.getElementById("add_info")
			})
			$("[name='add_form']").submit(function(e){
				if($("input[name='add_username']").val() == ""){
					e.preventDefault();
					$(".warn").html('<font color="red">提示：用户名不能为空</font>');
				}
			})
			/*验证用户名是否存在*/
			$(".warn").html("&nbsp;");
			$("[name='add_username']").keyup(function(){
				var add_name = $(this).val();
				if(add_name != ""){
					$.ajax({
						type:"post",
						url:"user_check.jsp",
						dataType:"html",
						data:{
							userName: add_name
						},
						cache:false,
						success:function(data){
							if(data == "用户名可以用"){
								$(".warn").html('<font color="green">提示：' + data + "</font>");
								$(this).focus();
							} else{
								$(".warn").html('<font color="red">提示：' + data + "</font>");
								$(this).focus();
							}
						}
					})
				}
				else{
					$(".warn").html('<font color="red">提示：用户名不能为空</font>');
				}
			})
			.blur(function(){
				$(".warn").html('&nbsp;');
			})
		})
		$(".update_info").click(function(){
			$(":text").addClass("nontxt");
			$(":text").focus(function(){
				$(this).removeClass("nontxt");
			})
			.mouseover(function(){
				$(this).removeClass("nontxt");
			})
			.blur(function(){
				$(this).addClass("nontxt");
			})
			.mouseout(function(){
				$(this).addClass("nontxt");
			})
			var update_id = $(this).attr('rel');
			$.ajax({
				type:"post",
				url:"user_update.jsp",
				cache:false,
				dataType:"json",
				data:{
					id:update_id
				},
				success:function(data){
					document.forms['add_form'].action="user_update_do.jsp?id="+update_id;
					$("input[name='add_name']").val(data.name).attr('readonly',true);
					$("input[name='add_username']").val(data.username).attr('readonly',true);
					$("input[name='add_password']").val(data.password);
					$("input[name='add_picPath']").val(data.picUrl);
					$("#imgs").attr("src",data.picUrl);
					$("input[name='add_sex']").each(function(i){
						$(this).attr("checked",false);
						if($(this).val() == data.sex)
						$(this).attr("checked",true);
					})
					$("input[name='add_position']").val(data.position);
					$("input[name='add_political']").val(data.political);
					$("input[name='add_birthday']").val(data.birthday);
					$("input[name='add_edulevel']").val(data.edulevel);
					$("input[name='add_email']").val(data.email);
					$("input[name='add_phone']").val(data.phone);
					$("[name='add_professional']").val(data.professional);
					$("[name='add_role']").find("option").each(function(i){
						$(this).attr("selected",false);
						if($(this).val() == data.role){
							$(this).attr("selected",true);
						}
					})
					$.dialog({
						title:'查看教工信息',
						content: document.getElementById("add_info")
					})
				}
			})
		})
		$("#update").hide();
		$(".photo").hover(
			function(){
				$("#update").show();
			},
			function(){
				$("#update").hide();
			}
		)
		var h = $(".right").height();
		$(".left").height(h);
		$('img').error(function(){
			this.src = "/InterStu/resources/image/man.GIF";
		})
	})
</script>
<title>留学生预科班</title>
</head>
<% 
	User cu =(User)session.getAttribute("user"); 
	List<User> list = new ArrayList<User>();
	String role = ParamUtil.getString(request,"role","");
	list = UserControl.getAllUsersByRole(role);
	request.setCharacterEncoding("UTF-8");
	String defaultPicUrl="../../resources/image/man.GIF";
	String path = "../../User/UserHeadImage/";
	//String picUrl = path + (String)session.getAttribute("picUrl");
	//if(session.getAttribute("picUrl")==null){
		//picUrl = defaultPicUrl;
	//}
	//session.removeAttribute("picUrl");
%>
<body>
<div class="header">
	<div class="title pr">
    	<a href="javascript:void(0);"><span class="update pa">个人信息</span></a>
        <span class="logout pa"><a class="hide" href="/InterStu/login/logout.jsp">退出</a></span>
    </div>
</div>
<div class="main">
	<div class="left">
	  <div class="infomation">
	     <div class="photo">
			<%
			String picUrl = cu.getPicUrl();
			%>
				<img width='60' height="60" src="<%=picUrl %>"/>
			</div>
			<div class="welcome">
				<%=cu.getName() %>,<br/>
				欢迎您使用！
			</div>
	  </div>   	
    	<div class="nav">
        	<ul>	
        	<%if(cu!=null&&cu.getRole().equals("1")){ %>
            	<li class="pa" id="magic_block"></li>
                <li><a href="/InterStu/pages/stuyear/stuyear_start.jsp">新学期设置</a></li>
                <li class="active"><a href="/InterStu/pages/users/user_all.jsp">用户管理</a></li>
                <%} %>
                <li><a href="/InterStu/pages/students/student_add.jsp">学生管理</a></li>
                <li><a href="/InterStu/pages/dictation/dictation_add.jsp">学生考核</a></li>
                <%if(cu!=null&&cu.getRole().equals("1")){ %>
                <li><a href="/InterStu/pages/assess/teacher_assess.jsp">教职人员管理</a></li>
                <%} %>
            </ul>
        </div>
    </div>
    <div class="right">
    	<div class="r1">
    	<table class="user tab">
    <tr>
    	<td>
    		<a class="current" href="/InterStu/pages/users/user_all.jsp">添加用户</a>
		</td>
		<td>
			<a href="/InterStu/pages/courseClass/set.jsp">课程分配</a>
		</td>
    </tr>
    </table>
    	<form action="user_all.jsp" name="condition" method="post">
    	<table class="table">
    		<caption>请选择</caption>
    		<tr>
    			<td>角色</td>
    			<td><input type="radio" value=""  name="role" checked/>全部  </td>
    			<td><input type="radio" value="1" name="role" <%=(role.equals("1"))?"checked":"" %>/>管理员  </td>
    			<td><input type="radio" value="0" name="role" <%=(role.equals("0"))?"checked":"" %>/>老师</td>
    		</tr>
    	</table>
    	</form>
        </div>
        <div class="r2">
        <table class='table'>
        <caption>查询结果</caption>
		<thead>
		<tr>
			<th width="16%">姓名</th>
			<th width="16%">用户名</th>
			<th width="16%">角色</th>
			<th width="16%">职务</th>
			<th width="16%">密码</th>
			<th width="20%">操作</th>
		</tr>
		</thead>
		<tbody>
		<% 
			for(int i=0;i<list.size();i++){
				User u = list.get(i);
		%>
		<tr>
			<td><a class="update_info" href="javascript:void(0);" rel=<%=u.getId() %>><%=u.getName() %></a></td>
			<td><%=u.getUsername() %></td>
			<td><%
					String r = u.getRole();
					if(r == "0" ||r.equals("0"))
					out.print("老师");
					else if(r == "1" || r.equals("1"))
					out.print("管理员");
					else
					out.print("其他教工");
				%>
			</td>
			<td><%=u.getPosition() %></td>
			<td><%=u.getPassword() %></td>
			<td>
				<a class="update_info" href="javascript:void(0);" rel=<%=u.getId() %>>修改</a>
			</td>
		</tr>
		<%
			}
		%>
		</tbody>
		</table>
		<br/>
		<a class='button add_info' id="openeradd">添加用户</a>
        </div>
    </div>
    <div id="add_info">
	    <form name="add_form" action="user_add_do.jsp" method="post">
		    <table>
		    <caption style="text-align: left" class="warn"></caption>
		    <tr>
		    	<td>姓名</td><td><input type="text" name="add_name" /></td>
		    	<td rowspan="5" colspan="2">
					<input type="hidden" id="updateImgs" name="add_picPath" value="<%=picUrl %>"/>
					<div class="photo pr">
						<img id="imgs" src="../../resources/image/man.GIF" width='100' height='100'  onerror= "this.src='../../resources/image/man.GIF'"/> 
						<a id="update" href="javascript:PopUpWindow('../../uploadimage.jsp',100,100,600,500);">修改照片</a>
					</div>
				</td>
		    </tr>
		    <tr>
		    	<td>用户名</td><td><input type="text" name="add_username" /></td>
		    </tr>
		    <tr>
		    	<td>密码</td><td><input type="text" value="123456" name="add_password"/></td>
		    </tr>
		    <tr>
		    	<td>性别</td><td>
		    	<input type="radio" name="add_sex" value="0" />男&nbsp;&nbsp;&nbsp;
		    	<input type="radio" name="add_sex" value="1" />女
		    	</td>
		    </tr>
		    <tr>
		    	<td>联系电话</td><td><input type="text" name="add_phone" /></td>
		    </tr>
		    <tr>
		    	<td>职务</td><td><input type="text" name="add_position" /></td>
		    	<td>角色</td><td>
		    	<select name='add_role'>
		    		<option value="0">老师</option>
					<option value="1">管理员</option>
					<option value="2">其他</option>
		    	</select></td>
		    </tr>
		    <tr>
		    	<td>政治面貌</td><td><input type="text" name="add_political" /></td>
		    	<td>生日</td><td><input onclick="SelectDate(this,'','','yyyy-MM-dd')" readonly style="cursor:pointer" type="text" name="add_birthday" /></td>
		    </tr>
		    <tr>
		    	<td>学历</td><td><input type="text" name="add_edulevel" /></td>
		    	<td>邮箱</td><td><input type="text" name="add_email" /></td>
		    </tr>
		    <tr>
		    	<td>科研情况</td>
		    	<td colspan="3">
		    	<textarea  name="add_professional" ></textarea>
		    	</td>
		    </tr>
		    <tr>
		    	<td colspan="4"><input type="submit"  value="确定"/></td>
		    </tr>
		    </table>
	    </form>
    </div>
</div>
<div class="footer">
	<p>版权所有：东北师范大学留学生预科部&nbsp;&nbsp;  蓝旭工作室开发</p>
</div>
</body>
</html>
